var t = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../../../mycomponent/yz_pay/yz_pay"), e = getApp();

Page({
    behaviors: [ a ],
    data: {
        language: "",
        credit2: 0,
        buttons: [],
        typename: "",
        recharge: "",
        ordersn: "",
        money: "",
        activatDes: {},
        pay_type: "",
        balanceLang: "余额",
        proportion_status: 0,
        payMuch: "",
        info: [],
        popshow: !1
    },
    onLoad: function(t) {
        t.store_id && this.setData({
            store_id: t.store_id
        });
    },
    onShow: function() {
        this.getStoreBalance();
    },
    selectSpecs: function(t) {
        var a = t.detail;
        for (var e in this.data.buttons) this.data.buttons[e].value == a && this.setData({
            radio: this.data.buttons[e].value,
            methodsArr: this.data.buttons[e]
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShareAppMessage: function() {},
    getStoreBalance: function() {
        var a = this, s = e.getNetAddresss("plugin.store-cashier.frontend.store.balance.balance.index");
        e._getNetWork({
            url: s,
            data: {
                store_id: this.data.store_id
            },
            success: function(e) {
                var s = e.data;
                if (1 == s.result) {
                    a.setData({
                        credit2: s.data.member_balance,
                        show_activity: s.data.show_activity,
                        buttons: s.data.pay_buttons,
                        title: s.data.title,
                        activatDes: s.data.activity,
                        proportion_status: s.data.proportion_status,
                        info: s.data,
                        is_open_recharge_order: 0 != s.data.is_open_recharge_order,
                        store: s.data.store
                    });
                    for (var n = 0; n < a.data.buttons.length; n++) a.data.buttons[n] && a.setData(t({}, "buttons[" + n + "].btclass", a.btnclass(a.data.buttons[n].value)));
                    for (var i in a.data.buttons) return void a.setData({
                        radio: a.data.buttons[i].value,
                        methodsArr: a.data.buttons[i]
                    });
                } else wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    moneyinp: function(t) {
        var a = t.detail.value;
        this.setData({
            money: a
        });
    },
    confirm: function(t) {
        var a = this;
        console.log(this.data.methodsArr.value);
        var s = this.data.methodsArr.value;
        this.setData({
            money: this.data.payMuch,
            pay_type: s
        });
        var n = e.getNetAddresss("plugin.store-cashier.frontend.store.balance.balance.recharge");
        n += "&client_type=2", n += "&app_type=wechat", n += "&pay_type_id=" + this.data.pay_type, 
        n += "&recharge_money=" + this.data.money, n += "&store_id=" + this.data.store_id, 
        e._getNetWork({
            url: n,
            success: function(t) {
                var n = t.data;
                if (1 == n.result) {
                    if ("88" == a.data.pay_type) return void wx.showModal({
                        title: "",
                        showCancel: !1,
                        content: "充值成功",
                        success: function(t) {
                            wx.navigateBack({
                                delta: 1
                            });
                        }
                    });
                    if (e._isTextEmpty(n.data.ordersn)) return void wx.showToast({
                        icon: "none",
                        title: "参数错误",
                        duration: 1500
                    });
                    a.setData({
                        ordersn: n.data.ordersn
                    }), a.rechargePay(s, n, n.data.ordersn);
                } else wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _handleKeyPress: function(t) {
        var a = t.currentTarget.dataset.num;
        if (-1 == a) return !1;
        switch (String(a)) {
          case ".":
            this._handleDecimalPoint();
            break;

          case "D":
            this._handleDeleteKey();
            break;

          case "S":
            this._handleConfirmKey();
            break;

          default:
            this._handleNumberKey(a);
        }
    },
    _handleDecimalPoint: function() {
        if (this.data.payMuch.indexOf(".") > -1) return !1;
        this.data.payMuch.length ? this.setData({
            payMuch: this.data.payMuch + "."
        }) : this.setData({
            payMuch: "0."
        });
    },
    _handleDeleteKey: function() {
        var t = this.data.payMuch;
        t.length <= 1 ? this.setData({
            payMuch: "0"
        }) : this.setData({
            payMuch: t.substring(0, t.length - 1)
        });
    },
    _handleConfirmKey: function() {
        if (this.data.store) {
            var t = this.data.payMuch;
            if (!t.length || 0 === Number(t)) return wx.showToast({
                icon: "none",
                title: "您目前未输入!",
                duration: 1500
            }), !1;
            t.indexOf(".") > -1 && t.indexOf(".") === t.length - 1 && (t = Number(t.substring(0, t.length - 1)).toFixed(2)), 
            t = Number(t).toFixed(2), this.setData({
                payMuch: t
            }), this.data.is_open_recharge_order ? this.setData({
                popshow: !0
            }) : this.confirmOrder();
        }
    },
    confirmOrder: function() {
        var t = this.data.payMuch;
        t && t > 0 ? (this.setData({
            payPrice: t,
            confirmOrderStatus: !0,
            isdisabled: !0
        }), this.confirm()) : (wx.showToast({
            icon: "none",
            title: "请输入正确的付款金额!",
            duration: 1500
        }), this.setData({
            confirmOrderStatus: !1,
            isdisabled: !1
        }));
    },
    _handleNumberKey: function(t) {
        var a = this.data.payMuch;
        if (a.indexOf(".") > -1 && a.substring(a.indexOf(".") + 1).length < 2 && this.setData({
            payMuch: a + t
        }), !(a.indexOf(".") > -1)) if (0 == t && 0 == a.length) this.setData({
            payMuch: "0."
        }); else {
            if (a.length && 0 === Number(a.charAt(0))) return void this.setData({
                payMuch: t
            });
            this.setData({
                payMuch: a + t
            });
        }
    },
    showOffMethod: function(t) {
        this.setData({
            popshow: t.detail.show1
        });
    }
});